import React, {useContext, useEffect} from 'react'
import {useDesigner, useWorkbench} from '@designable/react'
import {observer} from '@formily/react'
import {setSchema} from '../../design/service'
import {getFormById} from "../../design/service/api";
import {getParams} from "../../design/widgets";
import {previewProvider} from "../preview";

export const ActionsWidget = observer(() => {
    const designer = useDesigner()
    const workbench = useWorkbench()
    const {setTableName} = useContext(previewProvider)
    useEffect(() => {
        (async () => {
            const formId = getParams('form')
            if (!formId) return
            const formData = await getFormById(formId)
            const {json, tableName} = formData?.data || {}
            setSchema(designer, json)
            setTableName(tableName)
            workbench.type = 'PREVIEW'
        })()
    }, [])


    return (
        <></>
    )
})
